//
//  GKStatusController.m
//  寻宝之旅
//
//  Created by GK on 16/4/5.
//  Copyright © 2016年 GK. All rights reserved.
//

#import "XKStatusController.h"
#import "XBContact.h"
#import "XBContactCell.h"

@interface XKStatusController ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UIView *headView;
@property (weak, nonatomic) IBOutlet UIView *headLine;
@property (weak, nonatomic) IBOutlet UIButton *btnStatus;
@property (weak, nonatomic) IBOutlet UIButton *btnContact;

@property (weak, nonatomic) IBOutlet UITableView *tableViewOne;
@property (weak, nonatomic) IBOutlet UIView *containView;

@property (nonatomic ,strong) NSArray *arrContacts;

@end

@implementation XKStatusController





- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 默认选中第一个按钮
    [self clickBtnStatus:nil];
    
    self.tableViewOne.delegate = self;
    self.tableViewOne.dataSource = self;
    self.containView.hidden = NO;
    
    self.tableViewOne.rowHeight = 60;
    self.tableViewOne.tableFooterView = nil;
    
}

- (IBAction)clickBtnStatus:(id)sender
{
    //按钮变色
    self.btnStatus.selected = YES;
    self.btnContact.selected = NO;
    
    //滑块滚动
    CGFloat centerX = self.btnStatus.center.x;
    CGRect rect = self.headLine.frame;
    rect.origin.x = centerX - self.headLine.frame.size.width * 0.5;
    
    [UIView animateWithDuration:0.25 animations:^{
    self.headLine.frame = rect;
    }];
    
    //隐藏第二个view 显示第一个
    self.tableViewOne.hidden = YES;
    self.containView.hidden = NO;
    
}


- (IBAction)clickBtncontact:(id)sender
{
    //按钮变色
    self.btnStatus.selected = NO;
    self.btnContact.selected = YES;
    
    //滑块滚动
    CGFloat centerX = self.btnContact.center.x;
    CGRect rect = self.headLine.frame;
    rect.origin.x = centerX - self.headLine.frame.size.width * 0.5;
    [UIView animateWithDuration:0.25 animations:^{
        
        self.headLine.frame = rect;
    }];
    
    //隐藏第一个tableview 显示第二个
    self.tableViewOne.hidden = NO;
    self.containView.hidden = YES;
}


#pragma mark tableview datasource
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arrContacts.count;
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    XBContactCell *cell = [XBContactCell contactCell:tableView ];
    cell.contact = self.arrContacts[indexPath.row];
    return cell;
}
















//懒加载
- (NSArray *)arrContacts
{
    if(_arrContacts == nil)
        _arrContacts = [XBContact contact];
    return _arrContacts;
}



@end
